<?php
require_once("modules/interfaces/iconnection.class.php");
require_once("modules/debug.class.php");

abstract class Entity {
	protected $primaryKey=array();
	protected $table="";
	protected $fields=array();
	protected $connection = null;
	
	function __construct($connection) {
		__debug(__FILE__,__LINE__,"Entity: constructor");
		$this->connection=$connection;
	}
	
	/**
	 * @deprecated
	 * @param unknown_type $connection
	 * @return unknown_type
	 */
	public function setConnection($connection) {
		__debug(__FILE__,__LINE__,"Entity: constructor");
		$this->connection=$connection;
	}
	
	public function findById($id){
		
	}
	/**
	 * retrieve all occurence of the entity.
	 * @return unknown_type
	 */
	public function findAll(){
		__debug(__FILE__,__LINE__,"Entity::findAll() - retrieve all occurence.");
		$list = array();
		$sql="select * from ".$this->table;
		$list = $this->connection->executeToList($sql);
		return $list;
	}
	public function update(){
		$this->prepareUpdate();
		
	} 
	public function create(){
		$this->prepareCreate();
	} 
	public function delete(){
		
	}
	abstract function prepareUpdate();
	abstract function prepareCreate();
	
	/**
	 * retrieve corresponding linked entity from <code>$table</code> on <code>$key</code> key.
	 * @param string $table
	 * @param string $key
	 * @return array
	 */
	public function retrieve($table="",$key=""){
		if($table!="" && $key!="" ){
			
		}else{
			throw new PersistenceException("Entity::retrive() bad parameters");
		}
	}
}
?>